package github.sf.mod.calculate;

/**
 * 用于读取表达式的CharStream
 *
 * @author zhoup
 */
public class CharStream {
    private String dataText;
    private int pos = 0;
    private int col = 0;

    public CharStream(String text) {
        this.dataText = text;
    }

    public char peek() {
        if (eof()) {
            return 0;
        }
        return dataText.charAt(pos);
    }

    public char next() {
        if (eof()) {
            return 0;
        }
        char ch = dataText.charAt(pos++);
        col++;
        return ch;
    }

    public boolean eof() {
        return dataText.length() <= pos;
    }

    public int getCol() {
        return col;
    }
}
